﻿using System.Collections.Generic;

namespace HCore
{
    public class EntityManager
    {
        public Dictionary<int, BaseGameEntity> entityMap => _entityMap;

        private readonly Dictionary<int, BaseGameEntity> _entityMap = new Dictionary<int, BaseGameEntity>();
        private int _nextVaildId = 0;

        public void Dispose()
        {
            _nextVaildId = 0;
            _entityMap.Clear();
        }

        public void RegisterEntity(BaseGameEntity newEntity)
        {
            newEntity.SetID(++_nextVaildId);
            _entityMap.Add(newEntity.ID, newEntity);
        }

        public BaseGameEntity GetEntityFromID(int id)
        {
            Debug.Assert(_entityMap.ContainsKey(id), "<EntityManager::GetEntityFromID>: invalid ID");
            return _entityMap[id];
        }

        public void RemoveEntity(BaseGameEntity e)
        {
            _entityMap.Remove(e.ID);
        }
    }
}